import Vuex from 'vuex'
import ipHome from '@/net/ipHome'

Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    year: new Date().getFullYear(),
    userAdcd: '',
    energyType: '',
    gridHead: [
      { name: 'XZQHMC', value: '行政区划'},
      { name: 'SUMALL', value: '合计(安装总数)'},
      { name: 'finishRate', value: '完成率'},
      { name: 'SUMALL_MGD', value: '煤改电'},
      { name: 'SUMALL_MGQ', value: '煤改气'},
      { name: 'SUMALL_11', value: '安装录入'},
      { name: 'SUMALL_12', value: '施工中'},
      { name: 'SUMALL_13', value: '安装完毕'},
      { name: 'YUNXING_SL', value: '运行监控'},
      { name: 'SHENHE_SL', value: '验收'}
    ],
    gridData: [],
    energyTypeData: [
      { name: '全部', value: ''},
      { name: '煤改气', value: '010903'},
      { name: '煤改电', value: '010901'}
    ],
    sort: 1,
    sortData: [
      { name: '开工总数', value: 1 },
      { name: '完成率', value: 2 },
      { name: '安装完毕', value: 3 },
      { name: '运行数', value: 4 },
      { name: '审核数', value: 5 }
    ],
    company: ''
  },
  mutations: {
    changeYear (state, value) {
      state.year = value
    },
    changeUserAdcd (state, value) {
      state.userAdcd = value
    },
    changeEnergyType (state, value) {
      state.energyType = value
    },
    changeGridHead (state, value) {
      state.gridHead = value
    },
    changeGridData (state, value) {
      state.gridData = value
    },
    changeSort (state, value) {
      state.sort = value
    },
    changeCompany (state, value) {
      state.company = value
    }
  },
  actions: {
    getLedger ({commit, state}, vm) {
      vm.$notice.loading.show()
      ipHome.getIPHome({
        nd: state.year,
        quyxzqhdm: state.userAdcd,
        sorts: state.sort,
        nylxdm: state.energyType,
        quycjdm: state.company
      }).then(res => {
        res.forEach(value => {
          value.finishRate = value.WCL + '%'
        })
        commit('changeGridData', res)
        vm.$nextTick(() => {
          vm.$notice.loading.hide()
        })
      })
    }
  }
})
